import Vue from "vue";
import VueRouter from "vue-router";

import LoginView from "../views/LoginView.vue";
import UserManagerView from "../views/UserManagerView.vue";
import UserAddView from "../views/userManger/UserAddView.vue";
import UserListView from "../views/userManger/UserListView.vue";
import LoginUserInfoView from "../views/LoginUserInfoView.vue";
import OrderAddView from "../views/order/OrderAddView.vue";
import OrderListView from "../views/order/OrderListView.vue";
import FileUploadView from "@/views/file/FileUploadView.vue";
import FileDownloadView from "@/views/file/FileDownloadView.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "login",
    component: LoginView,
  },
  {
    path: "/userManager",
    name: "userManager",
    redirect: "/userManager/list", // 配置 默认进入列表页
    component: UserManagerView,
    children: [
      {
        path: "/userManager/add",
        name: "addUser",
        meta: {
          title: "添加用户",
        },
        component: UserAddView,
      },
      {
        path: "/userManager/list",
        name: "userList",
        meta: {
          title: "用户列表",
        },
        component: UserListView,
        props: true,
      },
      {
        path:"/orderManager/add",
        name:"add",
        meta:{
          title:"添加订单"
        },
        component: OrderAddView
      },
      {
        path:"/orderManager/list",
        name:"list",
        meta:{
          title:"订单列表"
        },
        component: OrderListView,
        props:true
      },
      {
        path: "/file/fileUpload",
        name: "FileUploadView",
        meta: {
          title: "文件上传",
        },
        component: FileUploadView,
      },
      {
        path: "/file/fileDownload",
        name: "FileDownloadView",
        meta: {
          title: "文件下载",
        },
        component: FileDownloadView,
      }

    ],
  },
  {
    path: "/loginUserInfo",
    name: "loginUserInfo",
    component: LoginUserInfoView,
  },
  {
    path: "/file",
    name: "file",
    component: FileUploadView,
    redirect: "/file/fileUpload",
  }
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
    // 路由切换时，改变页面标题、meta信息等
  }
  next();
});

export default router;
